package com.nowcoder.code.lcof;

public class JZ33 {

    public static void main(String[] args) {
        System.out.println(new JZ33().VerifySquenceOfBST(new int[]{8,4,6,12,16,14,10}));
    }
    public boolean VerifySquenceOfBST(int[] sequence) {
        if (sequence == null || sequence.length == 0) {
            return false;
        }
        return verify(sequence, sequence.length - 1, 0);
    }

    public boolean verify(int[] sequence, int root, int left) {
        if (root <= left ) {
            return true;
        }
        int i = 0;
        for (; i < root; i++) {
            if (sequence[root] < sequence[i]) {
                break;
            }
        }
        for (int j = i; j < root; j++) {
            if (sequence[j] < sequence[root]) {
                return false;
            }
        }

        return verify(sequence, root - 1, i) && verify(sequence, i - 1, left);


    }


}
